package com.dkts.oil.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dkts.oil.exception.OilException;
import com.dkts.oil.util.HttpUtils;
import com.dkts.oil.web.vo.request.OilImportRequest;
import com.dkts.oil.web.vo.request.TransferStationRequest;
import com.dkts.oil.web.vo.response.RouteDataResponse;
import com.dkts.oil.web.vo.response.subReq.PathPoints;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 储备库选址实现类
 * </p>
 *
 * @author heguanglong
 * @since 2025-04-10
 */
@Service
@Slf4j
public class OilRouteServiceImpl extends CheckSubWayOrWaterway {
    public RouteDataResponse transferStation(TransferStationRequest request) {
        String way = this.getRoadType(request);
        if (way == null) {
            throw new OilException("未选择正确的路线规划方式");
        }
        return this.route(way, request);
    }

    public RouteDataResponse route(String url, TransferStationRequest request) {
        JSONObject jsonObject = this.defaultRouteParam(request);
        try {
            JSONArray jsonObject1 = HttpUtils.postRoute(url + "/zryt/v1/truck", null, JSONObject.toJSONString(jsonObject));
            if (jsonObject1 == null) {
                throw new OilException("路线规划失败");
            }
            return new RouteDataResponse(jsonObject1);
        } catch (Exception e) {
            log.error("路线规划失败", e);
            throw new OilException("路线规划失败");
        }
    }
}
